package com.resou.reader.bookdetail.adapter;

import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.resou.reader.R;
import com.resou.reader.api.entry.CommentBean;
import com.resou.reader.utils.DateUtils;
import com.resou.reader.utils.PreferenceUtil;
import com.resou.reader.view.StarRatingBar;

import java.util.List;

/**
 * Author: 萤火虫
 * E-mail:  Allensuns@163.com
 * Description:
 * CreateTime: 2019-04 -11
 **/
public class CommmentDetailAdapter extends BaseQuickAdapter<CommentBean.ReviewlistBean, BaseViewHolder> {

    public CommmentDetailAdapter(int layoutResId, @Nullable List<CommentBean.ReviewlistBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CommentBean.ReviewlistBean item) {
        RequestOptions options = new RequestOptions();
        options.format(DecodeFormat.PREFER_RGB_565);
        Glide.with(mContext).load(item.getHead_pic()).apply(options).into((ImageView) helper.getView(R.id.comment_head));
        helper.setVisible(R.id.llComment, false)
                .setVisible(R.id.ivLookMore, true)
                .setVisible(R.id.starRatingBar, false).
                setText(R.id.tvUserName, item.getNickName() + "")
                .setText(R.id.tvCommentDes, item.getContent() + "")
                .setText(R.id.tvTime, DateUtils.getTheDayFromNow(item.getCreate_date()))
                .setTextColor(R.id.tvTime, mContext.getResources().getColor(R.color.color757575))
                .setImageResource(R.id.ivLike,
                        PreferenceUtil.getInstance(mContext).getlocalCommentPariseState(item.getId() + "") ? R.mipmap.ic_commentliked : R.mipmap.ic_commentlike)
                .setText(R.id.tvLikeNum, item.getPraisenum()==0?"点赞":item.getPraisenum() + "")
                .addOnClickListener(R.id.llPraise)
                .addOnClickListener(R.id.ivLookMore)
                .addOnClickListener(R.id.llCommentOnclickLister);
        TextView tvTime = helper.getView(R.id.tvTime);
        if (tvTime.getText().toString().equals("刚刚")) {
            helper.setTextColor(R.id.tvTime, mContext.getResources().getColor(R.color.theme_color));
        } else {
            helper.setTextColor(R.id.tvTime, mContext.getResources().getColor(R.color.color757575));
        }
    }
}
